package com.itheima.case1;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class ThreadDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
//        练习一
//        case1Thread c1 = new case1Thread();
//        case1Thread c2 = new case1Thread();
//
//        c1.setName("窗口一");
//        c2.setName("窗口二");
//        c1.start();
//        c2.start();

        //练习二
//        case2Thread c3 = new case2Thread();
//        case2Thread c4 = new case2Thread();
//        c3.setName("同学一");
//        c4.setName("同学二");
//        c3.start();
//        c4.start();

        //练习三
//        case3Runnable case3Runnable = new case3Runnable();
//        Thread t1 = new Thread(case3Runnable);
//        Thread t2 = new Thread(case3Runnable);
//        t1.start();
//        t2.start();

        //练习四
//        case4Runnable case4Runnable = new case4Runnable();
//        Thread t1 = new Thread(case4Runnable);
//        Thread t2 = new Thread(case4Runnable);
//        Thread t3 = new Thread(case4Runnable);
//        Thread t4 = new Thread(case4Runnable);
//        Thread t5 = new Thread(case4Runnable);
//        t1.start();
//        t2.start();
//        t3.start();
//        t4.start();
//        t5.start();

//        Case5Runnable case5Runnable = new Case5Runnable();
//        Thread t1 = new Thread(case5Runnable);
//        Thread t2 = new Thread(case5Runnable);
//        t1.setName("抽奖箱1");
//        t2.setName("抽奖箱2");
//        t1.start();
//        t2.start();

//        ArrayList arrayList = new ArrayList();
//        arrayList.add(10);
//        arrayList.add(5);
//        arrayList.add(20);
//        arrayList.add(50);
//        arrayList.add(100);
//        arrayList.add(200);
//        arrayList.add(500);
//        arrayList.add(800);
//        arrayList.add(2);
//        arrayList.add(80);
//        arrayList.add(300);
//        arrayList.add(700);
////        Case6Runnable case6Runnable = new Case6Runnable(arrayList);
////        Thread t1 = new Thread(case6Runnable);
////        Thread t2 = new Thread(case6Runnable);
////        t1.setName("抽奖箱1");
////        t2.setName("抽奖箱2");
////        t1.start();
////        t2.start();
//        Case7Runnable case7Runnable = new Case7Runnable(arrayList);
//        Thread t1 = new Thread(case7Runnable);
//        Thread t2 = new Thread(case7Runnable);
//        Thread t3 = new Thread(case7Runnable);
//        t1.setName("抽奖箱1");
//        t2.setName("抽奖箱2");
//        t3.setName("抽奖箱3");
//        t1.start();
//        t2.start();
//        t3.start();



        ArrayList arrayList = new ArrayList();
        arrayList.add(10);
        arrayList.add(5);
        arrayList.add(20);
        arrayList.add(50);
        arrayList.add(100);
        arrayList.add(200);
        arrayList.add(500);
        arrayList.add(800);
        arrayList.add(2);
        arrayList.add(80);
        arrayList.add(300);
        arrayList.add(700);
        MyCallable myCallable = new MyCallable(arrayList);

        FutureTask<Integer> f1 = new FutureTask(myCallable);
        FutureTask<Integer> f2 = new FutureTask(myCallable);
        FutureTask<Integer> f3 = new FutureTask(myCallable);
        Thread t1 = new Thread(f1);
        Thread t2 = new Thread(f2);
        Thread t3 = new Thread(f3);
        t1.setName("窗口一");
        t2.setName("窗口二");
        t3.setName("窗口三");

        t1.start();
        t2.start();
        t3.start();

        Integer r1 = f1.get();
        Integer r2 = f2.get();
        Integer r3 = f3.get();

        System.out.println(r1);
        System.out.println(r2);
        System.out.println(r3);



    }




}
